package com.cfl.usermodule.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cfl.usermodule.service.UserService;

@Controller
public class UserController {

	@Autowired
	private UserService userService;
	
	/**
	 * 获取用户
	 * @param name 用户名
	 * @return
	 */
	@RequestMapping("find_user")
	@ResponseBody
	public Object findUserByName(String name) {
		try {
			return userService.findUserByName(name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 获取用户
	 * @param name	用户名
	 * @param password	密码
	 * @return
	 */
	@RequestMapping("find_user_name_password")
	@ResponseBody
	public Object findUserByNameAndPassword(String name, String password) {
		try {
			return userService.findUserByNameAndPassword(name, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 添加用户
	 * @param name	用户名
	 * @param password	密码
	 * @return
	 */
	@RequestMapping("add_user_name_password")
	@ResponseBody
	public Boolean addUser(String name, String password) {
		try {
			return userService.addUser(name, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
}
